class_name VFXPlayer
extends Node2D

## 实现一些VFX相关接口
## 可能有的一些特殊处理可以在对应函数处理一下

#region 属性
var vfx_info:VFXInfo
var timer:CustomTimer
#endregion
#region 字段
#endregion
#region 信号
signal vfx_start
signal vfx_finished
#endregion

#region 基类方法
#endregion
#region 公共方法
func init():
	pass
func play():
	for child in get_children():
		if child is CPUParticles2D or child is GPUParticles2D:
			if child.one_shot and not child.emitting:
				child.emitting = true
	if vfx_info.duration >= 0:
		timer = GameCustomTimerSystem.create_timer(vfx_info.duration)
		timer.register_listener(timer.timer_finished,func(timer_result:CustomTimer.TimerResult):
			if timer_result == CustomTimer.TimerResult.Completed:
				stop()
		)
		timer.start_timer()
	vfx_start.emit()
func stop():
	if timer:
		queue_free()
		GameCustomTimerSystem.remove_timer(timer.id)
	vfx_finished.emit()
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _init(vfx_info:VFXInfo) -> void:
	self.vfx_info = vfx_info
#endregion
